package com.aaa.yunMall.service;

import com.aaa.yunMall.base.BaseService;
import com.aaa.yunMall.entity.User;
import com.aaa.yunMall.mapper.T_userMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LQY
 * @date 2020-07-08 16:18
 * 用户管理模块
 */
@Service
public class T_userService extends BaseService<User> {

    @Autowired
    private T_userMapper t_userMapper;

    /**
     * 查找所有用户
     * @return
     */
    public Object selecAllRoles(){
        List<User> t_users = t_userMapper.selectAll();
        return t_users;
    }

    /**
     * 根据姓名进行模糊查询
     * @return
     */
    public Object selectByName(String name){
        List<User> users = t_userMapper.selectByExample(name);
        if(null != users && 0 < users.size()){
            return users;
        }
        return null;
    }

    /**
     * 根据主键进删除单个用户
     * @param id
     * @return
     */
    public Integer deleteById(Integer id){
        Integer deleteByPrimaryKey = t_userMapper.deleteByPrimaryKey(id);
        if (0 < deleteByPrimaryKey){
            return deleteByPrimaryKey;
        }
        return -1;
    }

    /**
     * 批量删除用户
     * @param ids
     * @return
     */
    public Integer deleteByBath(List<Integer> ids){
        Integer deleteByList = t_userMapper.deleteByExample(ids);
        if(0 < deleteByList && null != deleteByList){
            return deleteByList;
        }
        return -1;
    }

    /**
     * 新增用户
     * @param user
     * @return
     */
   /* public ResultData addUser(T_user user){
        ResultData resultData = new ResultData();
        //判断用户是否已经存在
        t_userMapper(user.getUsername());
        if (0 < id){
            //用户已经存在
            return resultData.setCode(USER_EXIST.getCode()).setMsg(USER_EXIST.getMsg());
        }


        return null;
    }
*/
}
